<?php /*a:3:{s:69:"D:\phpstudy_pro\WWW\oldi-erp\app\admin\view\purchase\procurement.html";i:1747733331;s:62:"D:\phpstudy_pro\WWW\oldi-erp\app\admin\view\public\header.html";i:1747733208;s:61:"D:\phpstudy_pro\WWW\oldi-erp\app\admin\view\public\style.html";i:1747733208;}*/ ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ERP</title>

    <link rel="stylesheet" href="/static/css/element-ui@2.15.14.css">
    <script src="/static/js/vue.js"></script>
    <script src="/static/js/element-ui@2.15.14.js"></script>
    <script src="/static/js/axios.js"></script>
    <script src="/static/js/qs.js"></script>
    <script src="/static/js/config.js"></script>
    <script src="/static/js/echart.js"></script>




<style>
    html,
    body,
    #app {
        padding: 0;
        margin: 0;
    }    
    #contenr{
        padding: 0;
        margin: 10px;
    }
</style>

<body>
    <div id="app"  v-cloak>
        <div id="contenr">       
        <el-breadcrumb separator="/">
             
        <el-breadcrumb separator="/">
            <el-breadcrumb-item>首页</el-breadcrumb-item>
            <el-breadcrumb-item>采购管理</el-breadcrumb-item>
            <el-breadcrumb-item>待采购列表</el-breadcrumb-item>
        </el-breadcrumb>
        <br>
            <el-card >
                <div style="display: flex;align-items: center;justify-content: flex-start;">
                    <el-form :inline="true" :model="searchForm" size="small"  ref="refsearchForm">      
                   
                        <el-form-item label="供应商">
                            <el-select v-model="searchForm.s_id" placeholder="请选择供应商" filterable clearable>
                                <el-option v-for="item in supplier_list" :key="item.id" :label="item.name" :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>                       
    
                        <el-form-item>
                             
                            <el-button type="primary"  size="small" plain @click="getSearch" icon="el-icon-search" v-cloak>查询</el-button>
                            <el-button type="primary"  size="small"  @click="checkSubmits" icon="el-icon-edit-outline" v-cloak>批量生成采购单</el-button>
                            <el-button type="danger"  size="small"  @click="batchcancel" icon="el-icon-delete" v-cloak>批量取消采购单</el-button>
                        </el-form-item>          
                      </el-form>                   
               
                </div>  
                
                
                <el-table :data="tablelist"   style="width: 100%;margin-bottom: 20px;"  @selection-change="handleSelectionChange" row-key="id"  border >
                    <el-table-column   type="selection" width="55"></el-table-column>
                    <el-table-column   prop="id" label="ID" width="80"> </el-table-column>
                    <el-table-column   prop="supplier_name" label="供应商" > </el-table-column>  
                    <el-table-column   prop="count" label="采购的数量" ></el-table-column> 
                    <el-table-column   prop="buyer_name" label="采购员" ></el-table-column>   
                    <el-table-column  fixed="right" label="操作" width="220">
                        <template v-slot="{row}">
                            <el-button type="primary"  plain  icon="el-icon-view"  @click="lookUp(row)" >查看 </el-button>
                            <el-button type="danger"  plain  icon="el-icon-delete"  @click="cancel(row)" >取消 </el-button>
                        </template>
                    </el-table-column>
                </el-table>    
                <!-- page -->
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="searchForm.pagenum" :page-sizes="[20,50,100, 150, 300,500,1000,2000]"
                    :page-size="searchForm.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
                </el-pagination>  
            </el-card>        
             
    </div>

    <script>
        new Vue({
            el: '#app',
            data: function () {
                return {    
                    supplier_list:<?php echo $supplier_list; ?>,
                    total:0,   //分页总页数      
                    tablelist:[] ,              
                    searchForm: {                             
                        s_id: '',          
                        pagesize: 20,
                        pagenum: 1,
                        
                    },   
                   createForm:{
                        selectids:'',
                        type:'1'
                   },
                   cancelForm:{
                        selectids:'',
                        type:'1'
                   },
                   num:0,
                   
                    
                }
            },
            mounted(){        
                this.getSearch()
            },
            methods: {        

                async getDatalist() {
                    const res = await axios.post('/admin/purchase/procurement', {params: this.searchForm})
                        if (res.status !== 1) {
                            return this.$message.error(res.info);
                        }
                    this.total = res.info.total
                    this.tablelist = res.info.list
                },
                    
                handleSizeChange(newSize) {
                    this.searchForm.pagesize = newSize
                    this.getDatalist()
                },
                handleCurrentChange(newPage) {
                    this.searchForm.pagenum = newPage
                    this.getDatalist()
                },              
                getSearch() {
                    this.searchForm.pagenum = 1
                    this.getDatalist()
                },        
             // 获取多选值
                handleSelectionChange(res)
                {
                console.log(res);
                    var s_ids  = '';
                    res.forEach(item => {                      
                        s_ids += item.s_id+',';
                    })
                   this.cancelForm.selectids = s_ids.substring(0,s_ids.length-1);
                    this.createForm.selectids = s_ids.substring(0,s_ids.length-1);
                    console.log(this.createForm.selectids);
                },
         
              
                //批量生成采购
                async checkSubmits(){
                    if (this.createForm.selectids.length == 0 ){
                        return this.$message.error('请选择生成的供应商!');
                    }                
                    let loading = this.$loading({
                        lock: true,
                        text: '数据加载中···',
                        spinner: 'el-icon-loading',
                        background: 'rgba(0, 0, 0, 0.7)'
                        });
                    axios.post('/admin/purchase/create_purchase', {params: this.createForm}).then(res => {
                        loading.close()
                        if (res.status !== 1) {
                            return this.$message.error(res.info);                  
                        }
                    
                        this.$message.success('操作成功');                
                        this.getDatalist()
                    }).catch(err => {
                        console.log(err)
                    })                  
                }, 
                //批量取消采购单
                async batchcancel(){
                    if (this.cancelForm.selectids.length == 0 ){
                        return this.$message.error('请选择生成的供应商!');
                    } 
                    this.$confirm('确定要取消所选采购单吗？', '提示', {
                        confirmButtonText: '确定取消',
                        cancelButtonText: '取消取消',
                        closeOnClickModal: false, // 禁用点击遮罩关闭弹窗
                        type: 'warning'
                    }).then(() => {
                        let loading = this.$loading({
                            lock: true,
                            text: '取消采购单中···',
                            spinner: 'el-icon-loading',
                            background: 'rgba(0, 0, 0, 0.7)'
                        });
                        axios.post('/admin/purchase/cancel_purchase_itmes', {params: this.cancelForm}).then(res => {
                            loading.close()
                            if (res.status !== 1) {
                                return this.$message.error(res.info);             
                            }                    
                            this.$message.success('取消成功');
                            this.getDatalist()
                        }).catch(err => {
                            console.log(err)
                        })   
                        
                    }).catch(() => {
                        this.getDatalist()
                        this.$message.info('已取消修改');
                    });
                },
                //取消采购单
                async cancel(row){
                    this.cancelForm.selectids = row.s_id;
                    this.$confirm('确定要取消所选采购单吗？', '提示', {
                        confirmButtonText: '确定取消',
                        cancelButtonText: '取消取消',
                        closeOnClickModal: false, // 禁用点击遮罩关闭弹窗
                        type: 'warning'
                    }).then(() => {
                        let loading = this.$loading({
                            lock: true,
                            text: '取消采购单中···',
                            spinner: 'el-icon-loading',
                            background: 'rgba(0, 0, 0, 0.7)'
                        });
                        axios.post('/admin/purchase/cancel_purchase_itmes', {params: this.cancelForm}).then(res => {
                            loading.close()
                            if (res.status !== 1) {
                                return this.$message.error(res.info);             
                            }                    
                            this.$message.success('取消成功');
                            this.getDatalist()
                        }).catch(err => {
                            console.log(err)
                        })   
                        
                    }).catch(() => {
                        this.getDatalist()
                        this.$message.info('已取消修改');
                    });
                },
                //查看详情
                lookUp(row){
                    window.location.href = "/admin/purchase/procurement_itmes?id="+row.s_id  
                },
           
                                                        
            }             
        })
    </script> 


 </body> 
</html>
